package com.programmercarl.greed;

/**
 * https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/
 * 买卖股票的最佳时机Ⅱ   AC
 *
 * @author yulongtian
 * @create 2025-02-06 16:34
 */
public class Test04 {
    public static void main(String[] args) {

    }

    public int maxProfit(int[] prices) {
        int profit = 0;
        for (int i = 0; i < prices.length - 1; i++) {
            prices[i] = prices[i + 1] - prices[i];
            if (prices[i] > 0) {
                profit += prices[i];
            }
        }
        return profit;
    }

}
